import { ADD, MINUS, SETNAME } from './actionType'



// 为了生成action对象
export const add = payload => {
  return {
    type: ADD,
    payload
  }
}

// 为了生成action对象
export const minus = payload => {
  return {
    type: MINUS,
    payload
  }
}

// 异步减法操作,2秒后减去参数
// 必须调用同步操作，所以有异步action的前提是要有同步action
export const asyncMinus = payload => {
  return dispatch => {
    setTimeout(() => {
      dispatch(minus(payload))
    },2000)
  }
}

export const setName = payload => {
  return {
    type: SETNAME,
    payload
  }
}

// 异步设置名字操作，2秒后执行
export const asyncSetName = payload => {
  return dispatch => {
    setTimeout(() => {
      dispatch(setName(payload))
    },2000)
  }
}